local T = require('Module:Tool')
local V = require('Module:Value')

return {
    t = function(frame)
        local args = T.parseArgs(frame)
        args[2] = args[2] or '~'

        local glossary = V.glossary(args)

        local icon = glossary.icon
        local iconFormat = glossary.iconFormat
        local link = glossary.link
        local name = glossary.name

        local span = mw.html.create('span')
        span:addClass('glossary'):addClass('LOLContent'):addClass('TemplateG')

        if icon ~= nil and icon ~= false and mw.text.trim(tostring(icon)) ~= '' then
            span:wikitext(string.format('[[File:%s.%s|x20px|link=%s|alt=%s]]', icon, iconFormat, link, name))
        end

        if type(name) == 'string' and mw.text.trim(tostring(name)) ~= '' then
            if type(link) == 'string' and mw.text.trim(tostring(link)) ~= '' then
                span:wikitext(string.format('[[%s|%s]]', link, name))
            else
                span:wikitext(name)
            end
        end

        return tostring(span)
    end
}
-- [[Category:Module/Function]]
